#!/usr/bin/python2.4

# pylint: disable-msg=C6304

"""Tests the JDF tidal vectors read from xtide."""

import unittest

from matrix import DM
from matrix import LatLon
from matrix import Polar
from matrix import Ratio
import timeformat
import xtide_jdf


class TestXtideJDF(unittest.TestCase):

  def testIndex(self):
    vf_jdf = xtide_jdf.XtideJDF()
    vf_jdf.SetLatLonFuzzMinutes(50, 50)
    vf_jdf.SetTimeFuzzSeconds(10 * 3600)
    vf_jdf.OOR2011()
    ll_jdf = LatLon(DM(48, 27), -DM(124, 35))
    t0 = timeformat.ScanTimeString('2011-05-15 0638')
    self.assertEqual(Polar(abs(-2.2), 290), vf_jdf.Index(t0, ll_jdf))

    mid_flow = Ratio(6*3600+38, 6*3600+38+3600, 10*3600+42, -2.2, 0.0)
    mid_angle = Ratio(6*3600+38, 6*3600+38+3600, 10*3600+42, 290, 115)
    # print 'mid=%g' % (mid_flow,)
    # print 'mid_angle=%g' % (mid_angle,)
    self.assertAlmostEqual(
        abs(mid_flow),
        vf_jdf.Index(t0+3600, ll_jdf).Magnitude(),
        1)
    self.assertAlmostEqual(
        abs(mid_angle)/1e03,
        vf_jdf.Index(t0+3600, ll_jdf).Angle()/1e03,
        2)


def main():
  unittest.main()


if __name__ == '__main__':
  main()
